//
//  DPBlock.h
//  HigherOrderMessaging
//
//  Created by Ofri Wolfus on 16/12/06.
//  Copyright 2006 Ofri Wolfus. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import <HigherOrderMessaging/DPObjCRuntime.h>


@interface DPBlock : NSObject {
	void *_block_start, *_frame;
	unsigned _frame_length;
	CFMutableDictionaryRef info;
}

- (id)process;
- (void)setValue:(void *)val forKey:(id)key;
- (void *)valueForKey:(id)key;

@end

extern const void *__dp_block_finish;
extern id DPCreateBlock(void *location, void *frame, unsigned frame_length);


#define DPBlock(expressions...) \
({ \
	__label__ __dp_block_start, __dp_block_return; \
	DPBlock *_block = DPCreateBlock(&&__dp_block_start, __builtin_apply_args(), \
									method_getSizeOfArguments(dp_getMethod(self, _cmd))); \
	goto __dp_block_return; \
	__dp_block_start: \
		id each = (id)[_block valueForKey:@"each"]; \
		expressions; \
		//goto *__dp_block_finish; \
		return; \
	__dp_block_return: \
		_block; \
})
